perf: reuse List and remove ToArray call#4362
Conversation
SummaryPerformance optimization that removes unnecessary array allocation and reuses a list buffer in circular dependency detection. Critical IssuesNone found SuggestionsCircularDependencyDetector.cs: Verify buffer reuse correctnessThe buffer reuse optimization looks correct. The pathBuffer is mutated during the DFS traversal in HasCycleDfs. The PR correctly makes a defensive copy when a cycle is found. The logic is sound because:
TestScheduler.cs: Consider consistencyAt line 134 (after the PR), you're passing executableTests (a List) directly to GroupTestsByConstraintsAsync. However, at lines 246 and 277 in the same file, the code still creates arrays with ToArray() before calling the same method. For consistency and to avoid the same allocation overhead, consider removing those ToArray() calls too in a follow-up PR. VerdictAPPROVE - No critical issues. Clean performance optimization that saves ~2MB in allocations as claimed. |
ToArraycall inScheduleAndExecuteAsyncList<AbstractExecutableTest>inCircularDependencyDetector, clearing it each time.Should save around 2MB in
List<AbstractExecutableTest>andAbstractExecutableTest[]allocations